This is an example of migration to Unicode, using wide chars internally (UTF-16).

Two versions of TOOL are available :

Version using byte characters internally (not Unicode) :

Version using wide characters internally (Unicode UTF-16) :

New API types :

typedef char gtcharA;
typedef wchar_t gtcharW;
#ifdef TOOL_WIDE_API
#define gtchar gtcharW
#else
#define gtchar gtcharA
#endif

// Can be either [multi-]byte (if TOOL_WIDE_API *NOT* defined) or Unicode (if TOOL_WIDE_API defined)
typedef gtchar * GtString;
typedef const gtchar * GtCString;

// Always [multi-]byte
typedef gtcharA *GtStringA;
typedef const gtcharA *GtCStringA;

// Always Unicode
typedef gtcharW *GtStringW;
typedef const gtcharW *GtCStringW;

New API functions

  • GtBool API_StringA2W(GtCStringA pszA, GtStringW *ppszW);
  • GtBool API_StringW2A(GtCStringW pszW, GtStringA *ppszA);
  • GtBool API_SetCodePage(gtuint16 codepage);
  • gtuint16 API_GetCodePage();
  • GtBool API_UseWideChar(); // Returns GtTrue if wide chars are used internally
  • GtBool API_UserFnIsWide(); // Returns GtTrue if the user functions called by name (like demons, actions) receive wide chars
  • GtBool API_UserFnSetWide(GtBool b);

New API macros :

 #define GTCHARCOUNT(X) (sizeof(X) / sizeof(gtchar))

API changes :

Conversion [multi-]byte <--> wide characters

Two conversion strategies are used in the implementation :

In both cases, the API_SetCodePage function lets select the page code used by these conversion functions.

Callback management :

The following functions let register callbacks for various purposes. When linked with the wide version of TOOL, both the A and W version can be called. If you register both the byte and wide versions of a callback, then only the wide version will be called by TOOL

  • API_SetHelpCallbackFn
  • API_SetTranslationFn
  • API_SetErrorFn
  • GtDocRegister.   
  • GtDocSetLaunchEditorCallback

The following callbacks exported by gtdemons.dll are called by name. Only the wide version of TOOL will check for the W version of those callbacks. If both the A and W versions exist, then the W version is used. If neither the A nor W version is found, and the neutral name is found, then it's called as the A version.

  • GtdCpyWrtInfo
  • GtdDocInit
  • GtdInit

Note : The function API_UserFnSetWide has no impact on the calling convention.

File formats

The binary files saved with the wide version of TOOL 4.x contain UTF-16 strings. A Byte Order Mark (BOM) is inserted at the begining of the file.

The binary files saved with the version 3.x or with the byte version can be read by the wide version of TOOL.

  Text File .gtd .gtb without multibyte characters  
--> opened in "r" or "w" mode
Text file .gtd .gtb containing multibyte characters
--> opened in "r" or "w" mode
Binary file .gti .gte .gtm without BOM
--> opened in "rb" or "wb" mode
Binary file .gti .gte .gtm with BOM
--> opened in "rb" or "wb" mode
Version 3.x
Does not support Unicode.
  • Reading : ok
  • Writing : compatible with all versions.
  • Reading : will raise syntax errors because the additional bytes will be handled as normal characters.
  • Reading : ok
  • Writing : compatible with all versions.
  • Reading : not loaded, no error message .
Version 4.x in byte char mode.
Does not support Unicode.
  • Like version 3.x
  • Like version 3.x
  • Like version 3.x
  • Reading : not loaded, error message : "Unicode format not supported" .
Version 4.x in wide char mode.
Supports Unicode.
  • Like version 3.x
  • Reading : ok
  • Writing : not compatible with version 3.x and version 4.x in byte mode.
  • Reading : ok, lets read the old files, without conversion.
  • Writing : saved under UTF-16 format with BOM, even if it was read from a file under byte char format without BOM. Not compatible with version 3.x and version 4.x in byte mode.
  • Reading : ok
  • Writing :  not compatible with version 3.x and version 4.x in byte mode.